﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using ZFSDomain.Common.UserControls;
using ZFSDomain.Interface.User;

namespace ZFSDomain.ViewDialog.Step
{
    /// <summary>
    /// 消息处理
    /// </summary>
    public class MsgViewDlg : IMsgDialog
    {
        private MsgBox view;
        

        public void BindViewModel<TViewModel>(TViewModel viewModel) where TViewModel : ViewModelBase
        {
            GetDialog().DataContext = viewModel;
        }

        public void Close()
        {
            GetDialog().Close();
        }

        public bool? ShowDialog()
        {
            var dialog = GetDialog();
            dialog.ShowDialog();
            return dialog.Result;
        }

        private MsgBox GetDialog()
        {
            if (view == null)
            {
                view = new MsgBox();
                view.Closing += (obj, e) => {
                    view = null;
                };
            };
            return view;
        }
    }
}
